package com.tanhua.app.controller;

import com.tanhua.app.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;

    @PostMapping(value = "/location",name="上报探花用户的地理位置")
    public ResponseEntity location(@RequestBody Map<String,String> map) throws IOException {

        double x_latitude =Double.parseDouble(map.get("latitude"));
        double y_longitude =Double.parseDouble(map.get("longitude"));
        String addrStr = map.get("addrStr");


        //假地址 匹配数据库
        x_latitude=40.169419;
        y_longitude=116.635672;
        addrStr="黑马程序员(顺义校区)";

        System.out.println("开始上传地理位置了..");
        //上报地理位置
        return baiduService.toAddr(x_latitude,y_longitude,addrStr);
    }

}
